<template>
	<view class="">
		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :back-top="true" emptyText="附近30km暂时没有救援队">
			<view class="" style="padding-top: 30rpx;">
				<view class="item-con" v-for="(item,index) in dataList" :key="index" @tap.stop="onItemClick(item)">
					<view class="item">
						<view class="item-top flex-row justify-between">
							<view class="item-top-title clamp">{{item.name}}</view>
							<view class="item-top-right">{{item.distance}}KM</view>
						</view>
						<view class="item-dir clamp2">{{item.introduction}}</view>
						<view class="item-dis clamp2">地址：{{item.address}}</view>
						<view class="item-bottom flex-row justify-center">
							<view class="btn" hover-class="hover-opacity" @tap.stop="openMap(item)">导航</view>
							<view class="btn" hover-class="hover-opacity" style="margin-left: 40rpx;" @tap.stop="callphone(item.phone)">拨打电话</view>
						</view>
					</view>
				</view>
			</view>
		</s-pull-scroll>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
export default {
	data() {
		return {
			longitude: '',
			latitude: '',
			dataList: []
		};
	},
	onLoad(options) {
		this.longitude = options.longitude;
		this.latitude = options.latitude;
		this.refresh();
	},
	methods: {
		onItemClick(item){
			getApp().globalData.serverInfo=item;
			this.navTo('/pages_servce/servce/creat');
		},
		openMap(item){
			if(!item.latitude || !item.longitude){
				this.$util.msg('当前位置错误!');
				return
			}
			uni.openLocation({
				address:item.province+ item.city+ item.address,
				latitude:item.latitude-0,
				longitude:item.longitude-0
			})
		},
		pullDown(pullScroll) {
			setTimeout(() => {
				this.loadData(pullScroll);
			}, 200);
		},
		async loadData(pullScroll) {
			const data = {
				longitude: this.longitude,
				latitude: this.latitude,
				pageNo: pullScroll.page,
				pageSize: '10'
			};
			if (pullScroll.page == 1) this.dataList = [];
			const res = await this.$request('rescue/list', data, { showLoading: true });
			if (res.result == 0) {
				this.dataList = this.dataList.concat(res.data.list);
				pullScroll.endByPage(Math.ceil(res.data.count / 10), res.data.list);
			} else {
				this.$util.msg(res.resultNote);
			}
		}
	}
};
</script>

<style scoped lang="scss">
.item-con {
	padding: 20rpx;
}
.item {
	border-radius: 20rpx;
	padding: 30rpx;
	background: #ffffff;
}
.item-top-title {
	font-weight: bold;
	max-width: 80%;
	font-size: 34rpx;
}
.item-top-right {
	font-size: 26rpx;
	color: #999;
}
.item-dir {
	padding-top: 16rpx;
	color: #666;
	font-size: 26rpx;
}
.item-dis {
	margin-top: 16rpx;
	font-size: 24rpx;
	color: #8C8D8F;
	padding: 20rpx 30rpx;
	background: #F7F9FB;
}
.item-bottom {
	padding-top: 20rpx;
}
.btn {
	height: 66rpx;
	line-height: 66rpx;
	font-size: 26rpx;
	color: #ffffff;
	width: 250rpx;
	text-align: center;
	background: $uni-color-bg;
	border-radius: 33rpx;
}
</style>
